/*************************************************************
 * Title: 
 * Description: 
 * Author: Snow Huang
 * Email: Shaobin.Software@gmail.com Shaobin_Software@163.com
 * CreateTime: 2010-7-11 下午12:03:22
 * Copyright © 落羽社区 All right reserved
 ************************************************************/
package snow.core.domain.action;

import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;

import snow.biz.system.dao.UserDao;
import snow.biz.system.model.User;
import snow.core.util.constants.ApplicationConstants;
import snow.core.util.toolkit.ServletHelper;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 */
public abstract class BaseAction<Result> extends ActionSupport {

	private boolean success;

	private Result result;

	private UserDao userDao;

	/**
	 * @return
	 * @see com.opensymphony.xwork2.ActionSupport#getActionErrors()
	 */
	@JSON(serialize = false)
	public Collection<String> getActionErrors() {
		return super.getActionErrors();
	}

	/**
	 * @return
	 * @see com.opensymphony.xwork2.ActionSupport#getActionMessages()
	 */
	@JSON(serialize = false)
	public Collection<String> getActionMessages() {
		return super.getActionMessages();
	}

	/**
	 * @return
	 * @deprecated
	 * @see com.opensymphony.xwork2.ActionSupport#getErrorMessages()
	 */
	@Deprecated
	@JSON(serialize = false)
	public Collection<String> getErrorMessages() {
		return super.getErrorMessages();
	}

	/**
	 * @return
	 * @deprecated
	 * @see com.opensymphony.xwork2.ActionSupport#getErrors()
	 */
	@Deprecated
	@JSON(serialize = false)
	public Map<String, List<String>> getErrors() {
		return super.getErrors();
	}

	/**
	 * @return
	 * @see com.opensymphony.xwork2.ActionSupport#getFieldErrors()
	 */
	@JSON(serialize = false)
	public Map<String, List<String>> getFieldErrors() {
		return super.getFieldErrors();
	}

	/**
	 * @return
	 * @see com.opensymphony.xwork2.ActionSupport#getLocale()
	 */
	@JSON(serialize = false)
	public Locale getLocale() {
		return super.getLocale();
	}

	@JSON(serialize = false)
	public HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	@JSON(serialize = false)
	public HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}

	/**
	 * @return the result
	 */
	public Result getResult() {
		return result;
	}

	@JSON(serialize = false)
	public HttpSession getSession() {
		return ServletHelper.getSessionFrom(getRequest());
	}

	/**
	 * @return
	 * @see com.opensymphony.xwork2.ActionSupport#getTexts()
	 */
	@JSON(serialize = false)
	public ResourceBundle getTexts() {
		return super.getTexts();
	}

	/**
	 * @return the userDao
	 */
	@JSON(serialize = false)
	public UserDao getUserDao() {
		return userDao;
	}

	@JSON(serialize = false)
	protected User getCurrentUser() {
		String username = (String) getSession().getAttribute(ApplicationConstants.SESSION_USERNAME);
		User user = userDao.findUser(username);
		return user;
	}

	/**
	 * @return the success
	 */
	public boolean isSuccess() {
		return success;
	}

	/**
	 * @param result
	 *            the result to set
	 */
	public void setResult(Result result) {
		this.result = result;
	}

	/**
	 * @param success
	 *            the success to set
	 */
	public void setSuccess(boolean success) {
		this.success = success;
	}

	/**
	 * @param userDao
	 *            the userDao to set
	 */
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

}
